package com.ziyun.erp.modules.micro.service.imp;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ziyun.erp.common.utils.MD5;
import com.ziyun.erp.modules.micro.dao.MicroDao;
import com.ziyun.erp.modules.micro.entity.ConfigAnonymousRequestEntity;
import com.ziyun.erp.modules.micro.service.MicroService;
import io.renren.common.exception.RRException;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;

import java.net.InetAddress;

/**
 * @author zh
 * @date 2018/8/611:26
 */
@Service("microService")
public class MicroServiceImp extends ServiceImpl<MicroDao,ConfigAnonymousRequestEntity> implements MicroService {
    //获取微服务匿名钥匙
    public String getAnonymousKey() {
        ConfigAnonymousRequestEntity configAnonymousRequest = new ConfigAnonymousRequestEntity();
        try {
            configAnonymousRequest.setAnonymousKey(
                    MD5.getMD5Code(RandomStringUtils.randomAlphabetic(10) + System.currentTimeMillis()));
            configAnonymousRequest.setIp(InetAddress.getLocalHost().getHostAddress());
            this.insert(configAnonymousRequest);
        }catch (Exception e){
            throw new RRException("生成签名异常:" +e.getMessage());
        }
        //return configAnonymousRequest.getAnonymousKey();
        return configAnonymousRequest.getId();
    }
}
